package Demo14;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-12-21
 * Time: 15:55
 */

/* 请在这里填写答案 */
interface Goods{
    public String getName();
    public double getPrice();
}
class Book implements Goods{
    public String name;
    public double price;

    public Book(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public double getPrice() {
        return price;
    }
}
class Drink implements Goods{
    public String name;
    public double price;

    public Drink(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public double getPrice() {
        return price;
    }
}
class ShopCar{
    public Goods goods[];
    public int address;
     public static int num = 0;

    public ShopCar(int n) {
        goods = new Goods[n];
    }

    public Goods[] getGoods() {
        return goods;
    }

    void add(Goods good){
        if (num< goods.length){
            goods[num] = good;
            num++;
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }
    void remove(int n){
        for (int i = n; i < goods.length-1; i++) {
            goods[i] = goods[i+1];
        }
        goods[num-1]=null;
        num--;
    }
    double check(){
        double sum = 0;
        for (int i = 0; i < goods.length-1; i++) {
            sum += goods[i].getPrice();
        }
        return sum;
    }

}

public class Main {
    public static void main(String[] args) {
        int n;
        Scanner scan=new Scanner(System.in);
        n=scan.nextInt();
        ShopCar sc=new ShopCar(n);
        sc.add(new Book("Java程序设计",78.5));
        sc.add(new Book("图像处理",44.5));
        sc.add(new Book("高等数学",34.8));
        sc.add(new Drink("绿茶",2.5));
        sc.add(new Drink("雪碧",3.5));
        sc.add(new Drink("可乐",5.5));
        sc.remove(3);
        for(int i=0;i<sc.getGoods().length;i++){
            if(sc.getGoods()[i]!=null)
                System.out.println("商品名称："+sc.getGoods()[i].getName()+"，价格："+sc.getGoods()[i].getPrice());
        }
        System.out.println("结账："+sc.check());
    }

}